//
//  PaysucessTableViewCell.m
//  shanHaiHuiApp
//
//  Created by DS on 2018/8/27.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "PaysucessTableViewCell.h"

#import "CardHeaderView.h"

#import "CardTableViewCell.h"

@implementation PaysucessTotalTableViewCell

- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    
    if (self = [super initWithCellIdentifier:cellID]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
       
        _orderNo = [UILabel addLableFont:11 WithColor:getColor(@"323232")];
        self.orderNo.text = @"12344";
        
        _totalMoney = [UILabel addLableFont:14 WithColor:getColor(@"EC4350")];
        
        self.totalMoney.text = @"yuii";
        
        _lineView = [UIView addLineViewColor:getColor(@"F0F0F0")];
        
        [self sd_addSubviews:@[self.orderNo,self.totalMoney,self.lineView]];
    
        [self layOutFrame];
    }
    
    return self;
}


- (void)layOutFrame{
    
    ws(self)
    
    [self.orderNo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.centerY.mas_equalTo(weakself.mas_centerY);
    }];
    
    [self.totalMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.mas_centerY);
        
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(UNIT_HEIGHT(5));
    }];
    
    
}

@end

@implementation PaysucessCashTableViewCell

- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    
    if (self = [super initWithCellIdentifier:cellID]) {
        
           self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _cashImageView = [UIImageView addImgWithImage:@"huiyuanka"];
        
        _cashLabel = [UILabel addLableFont:14 WithColor:getColor(@"666666")];
        
        _moneyLabel = [UILabel addLableFont:14 WithColor:getColor(@"323232")];
        
        _lineView = [UIView addLineViewColor:getColor(dividerColor)];
        
        
        [self sd_addSubviews:@[self.cashImageView,self.cashLabel,self.lineView,self.moneyLabel]];
        
        [self layOutFrame];
    }
    
    return self;
}


- (void)layOutFrame{
    
    ws(self)
    
    
    [self.cashImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.centerY.mas_equalTo(weakself.mas_centerY);
        make.width.mas_equalTo(UNIT_WIDTH(21));
        make.height.mas_equalTo(UNIT_HEIGHT(17));
    }];
    
    [self.cashLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.cashImageView.mas_right).offset(UNIT_WIDTH(10));
        make.centerY.mas_equalTo(weakself.mas_centerY);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
         make.centerY.mas_equalTo(weakself.mas_centerY);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(UNIT_HEIGHT(1));
    }];
   
}

@end

@implementation PaysucessPlaceTableViewCell

- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    
    if (self = [super initWithCellIdentifier:cellID]) {
        
          self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _moneyLabel = [UILabel addLableFont:14 WithColor:getColor(@"323232")];
        
      
        
        _lineView = [UIView addLineViewColor:getColor(@"F0F0F0")];
        
        [self sd_addSubviews:@[self.moneyLabel,self.lineView]];
        
        [self layOutFrame];
    }
    
    return self;
}


- (void)layOutFrame{
    
    ws(self)
    
   
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.mas_centerY);
        
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(UNIT_HEIGHT(1));
    }];
    
    
}

@end

@interface PaysucessGoodTableViewCell()<UITableViewDelegate,UITableViewDataSource>

Strong UITableView * tableView;



//头部视图
Strong UIView * headerView;

Strong UIImageView * picImageView;
Strong UILabel * nameLabel;
Strong UILabel * countLabel;
Strong UILabel * moneyLabel;
Strong UIView * lineView;


@end

@implementation PaysucessGoodTableViewCell

- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    
    if (self = [super initWithCellIdentifier:cellID]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        [self addSubview:self.tableView];
       
    }
    
    return self;
}

- (UIView *)headerView{
    
    if (!_headerView) {
        
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, UNIT_HEIGHT(100))];
        
        _picImageView = [UIImageView new];
        _picImageView.layer.masksToBounds = YES;
        _picImageView.image = [UIImage imageNamed:@"shanhaihuilogo"];
        
        
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = DEF_FontSize_14;
        _nameLabel.textColor = getColor(@"323232");
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.numberOfLines = 0;
        _nameLabel.text = @"三只松鼠";
        
        _countLabel = [[UILabel alloc] init];
        _countLabel.font = DEF_FontSize_14;
        _countLabel.textColor = getColor(@"666666");
        _countLabel.text = @"10";
        
        
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.font = DEF_FontSize_14;
        _moneyLabel.textColor = getColor(@"323232");
        _moneyLabel.text = @"￥99.6";
        
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = getColor(dividerColor);
        
        [_headerView sd_addSubviews:@[self.picImageView,self.nameLabel,self.countLabel,self.moneyLabel,self.lineView]];
        
       
        ws(self)
        
        [self.picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(UNIT_WIDTH(15));
            make.top.mas_equalTo(UNIT_HEIGHT(10));
            make.height.mas_equalTo(UNIT_HEIGHT(65));
            make.width.mas_equalTo(UNIT_WIDTH(65));
        }];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakself.picImageView.mas_right).offset(UNIT_WIDTH(15));
            make.top.mas_equalTo(UNIT_HEIGHT(15));
            make.right.mas_equalTo(UNIT_WIDTH(-14));
        }];
        
        [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakself.picImageView.mas_right).offset(UNIT_WIDTH(15));
            make.bottom.mas_equalTo(UNIT_HEIGHT(-15));
            make.width.mas_equalTo(UNIT_HEIGHT(100));
        }];
        
        [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(UNIT_WIDTH(-14));
            make.bottom.mas_equalTo(UNIT_HEIGHT(-15));
            make.width.mas_equalTo(UNIT_HEIGHT(100));
        }];
        
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakself.moneyLabel.mas_bottom).offset(10);
            make.left.mas_equalTo(0);
            make.height.mas_equalTo(0.5);
            make.right.mas_equalTo(0);
        }];
        
        
    }
    
    return _headerView;
    
}


//tabelView
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - UNIT_HEIGHT(40) - height20) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.sectionFooterHeight = .01;
        _tableView.sectionHeaderHeight = .01;
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0.01)];
        _tableView.tableHeaderView = self.headerView;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.backgroundColor = getColor(whiteColor);
        _tableView.scrollEnabled = NO;
    }
    return _tableView;
}
#pragma mark - <UITableViewDelegate , UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.sphArr.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CardTableViewCell * cell = [CardTableViewCell cellForTableView:tableView];
    
    cell.model = self.sphArr[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return UNIT_HEIGHT(130);
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}

- (void)setSphArr:(NSMutableArray *)sphArr{
    
    _sphArr = sphArr;
 
    _tableView.height = UNIT_HEIGHT(100) + self.sphArr.count  * UNIT_HEIGHT(130);
    
    
}

- (void)setModel:(PayMentGoodModel *)model{
    
    _model = model;
  
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:model.imagepfilename]];
    self.nameLabel.text = model.spmc;
    self.countLabel.text = [NSString stringWithFormat:@"×%@",model.xssl];
    self.moneyLabel.text = [NSString stringWithFormat:@"￥%@",model.xsje];
    
    
}

@end




